{%  extends "admin/common/admin_base.html" %}
{% block title -%}
    角色管理
{% endblock %}
{% block page_title -%}角色管理{% endblock %}
{% block page_btn_name -%}编辑角色{% endblock %}
{% block content -%}
    <section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="{{ url_for('adminrole.edit') }}" onsubmit="return false" >
            <input type="hidden" name="id" value="{{ data.id }}">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab1" data-toggle="tab">基本参数</a></li>
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"><i class="fa fa-list"></i> 返回</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab1">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">角色名称</label>
                                <div class="col-sm-7"><input class="form-control" name="role_name" value="{{ data.role_name  }}" placeholder="角色名称"></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">角色类型</label>
                                <div class="col-sm-7">
                                    <select class="form-control select2" name="role_type" style="width:100%;">
                                        {% for type in role_type %}
                                        <option value="{{ type }}" {% if data.role_type == type %}selected="selected"{% endif %}  >{{ role_type[type] }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">角色描叙</label>
                                <div class="col-sm-7">
                                <input class="form-control" name="describe" placeholder="角色描叙" value="{{ data.describe }}">
                                </div>
                            </div>
                            <div class="form-group" id='pri_'>
                                <label class="col-sm-2 control-label">角色权限</label>
                                <div class="col-sm-7 rule_node">
                                {% for v in menu -%}
                                    <p class='left1'>
                                        <label class="checkbox-inline">
                                            <input type="checkbox" name="role_pri" value="{{ v.id }}" {% if v.id|string in data.role_pri %}checked="checked"
                        {% endif %} class="minimal">{{ v.pri_name }}
                                        </label>
                                    </p>
                                    {% for vv in v.child -%}
                                        <p class='left2'>
                                            <label class="checkbox-inline">
                                                <input type="checkbox" name="role_pri" value="{{ vv.id }}" {% if vv.id|string in data.role_pri %}checked="checked"
                        {% endif %} class="minimal">{{ vv.pri_name }}
                                            </label>
                                        </p>
                                        {% for vvv in vv.child -%}
                                            <p class='left3 p_left'>
                                                <label class="checkbox-inline">
                                                    <input type="checkbox" name="role_pri" value="{{ vvv.id }}" {% if vvv.id|string in data.role_pri %}checked="checked"
                        {% endif %} class="minimal">{{ vvv.pri_name }}
                                                </label>
                                            </p>
                                        {%- endfor %}
                                    {%- endfor %}
                                {%- endfor %}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-7">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            </div>
                            <div class="btn-group pull-left">
                                <button type="reset" class="btn btn-warning">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>
    <script type="text/javascript">
        $(function(){
           change_($('select[name="role_type"]'));
            /*ajax页面加载icheck，有该控件的页面才需要*/
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            });

            /*ajax页面加载icheck，有该控件的页面才需要*/
            $(".select2").select2({language:"zh-CN"});
            $('select[name="role_type"]').change(function(){
                change_($(this));
            })

            function change_(obj)
            {
                var val = obj.val();
                if(val == 1)
                   $('#pri_').hide()
                else
                   $('#pri_').show()
            }
        })
    </script>
{% endblock %}